$(document).ready(function() {
    $('#manage-function-form').submit(function() {
        var functionId = $('#functionId').val() || 0;
        var value = $('#value').val();
        var errors = new Array();
        
        if (value == '') {
            errors.push('Please enter value.');
        }
        
        if (errors.length == 0) {
            $.ajax({
                method: 'post',
                url: 'ajax.do?method=manageFunction',
                data: {
                    functionId: functionId,
                    value: value,
                },
                success: function(result) {
                    alert('Value has been saved!');
                    window.location.replace('fuzzy.do?method=list');
                    
                }
            });
        } else {
            displayMessages(errors, '#messages');
        }
        
        return false;
    });
});